/*
 * p10635.cpp
 *
 *  Created on: 2013-4-23
 *      Author: zy
 */

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int maxn = 250 * 250 + 1;
const int INF = 0x7fffffff;
int a[maxn], d[maxn], num[maxn];
int main()
{
	int T;
	scanf("%d", &T);
	for (int cas = 1; cas <= T; cas++)
	{
		int n, p, q, x;
		scanf("%d%d%d", &n, &p, &q);
		memset(num, 0, sizeof(num));
		for (int i = 1; i <= p + 1; i++)
		{
			scanf("%d", &x);
			num[x] = i;
		}
		n = 0;
		for (int i = 1; i <= q + 1; i++)
		{
			scanf("%d", &x);
			if (num[x]) a[++n] = num[x];
		}
		int ans=1;
		d[1]=a[1];
		for(int i=2;i<=n;i++)
		{
			if(a[i]>d[ans])d[++ans]=a[i];
			else
			{
				int low=lower_bound(d+1,d+ans+1,a[i])-d;
				d[low]=a[i];
			}
		}
		printf("Case %d: %d\n",cas,ans);
	}
	return 0;
}
